home *** CD-ROM | disk | FTP | other *** search
- class Chopper
- {
- var refGame;
- var bmpChopper;
- var bmpBackRot;
- var bmpTopRot;
- var bmpExplode;
- var bmpWheels;
- var bmpTmp;
- var bmpCanvas;
- var width;
- var height;
- var acc;
- var accMax;
- var speed;
- var position;
- var bOnPlatform;
- var screenPos;
- var frame;
- var backFrame;
- var topFrame;
- var frameExp;
- var screenH;
- var airDrag;
- var rotation;
- var maxRot;
- var bShowWheels;
- var frameWheels;
- var fuel;
- var aHostTaken;
- var energy;
- var bDestroyed;
- var bShowExplosion;
- var bTurn;
- var turnDir;
- var turnDelay;
- var chafs;
- var bChaf;
- var chafDelay;
- var bShot;
- var shotDelay;
- var cannonAngle;
- var cannonAngleMin;
- var cannonAngleMax;
- var bAutoAim;
- var aCannonPos;
- var aTopPos;
- var rope;
- var ropePos;
- var aBottom;
- var ropeEndPos;
- var bRopePress;
- var bGodMode = false;
- var maxChafs = 5;
- var bFuelSnd = false;
- var maxLoad = 5;
- var unloadTime = 20;
- function Chopper(newPos)
- {
- this.refGame = Game.getInstance();
- this.bmpChopper = flash.display.BitmapData.loadBitmap("chopper");
- this.bmpBackRot = flash.display.BitmapData.loadBitmap("backRot");
- this.bmpTopRot = flash.display.BitmapData.loadBitmap("topRot");
- this.bmpExplode = flash.display.BitmapData.loadBitmap("explosion0");
- this.bmpWheels = flash.display.BitmapData.loadBitmap("chopper wheels");
- this.bmpTmp = new flash.display.BitmapData(130,58);
- this.bmpCanvas = Game.bmpChopper;
- this.width = 130;
- this.height = 53;
- this.acc = new flash.geom.Point(0,0);
- this.accMax = new flash.geom.Point(15,5);
- this.speed = new flash.geom.Point(0,0);
- this.position = newPos.clone();
- this.position.y += 27;
- this.bOnPlatform = false;
- this.screenPos = new flash.geom.Point();
- this.frame = 3;
- this.backFrame = 1;
- this.topFrame = 1;
- this.frameExp = 0;
- this.screenH = Game.screenH;
- this.airDrag = 0.98;
- this.rotation = 0;
- this.maxRot = 0.5235987755982988;
- this.bShowWheels = true;
- this.frameWheels = 6;
- this.fuel = 100;
- this.aHostTaken = new Array();
- this.energy = 5;
- this.bDestroyed = false;
- this.bShowExplosion = false;
- this.bTurn = false;
- this.turnDir = -1;
- this.turnDelay = 0;
- this.chafs = this.maxChafs;
- this.bChaf = false;
- this.chafDelay = 0;
- this.bShot = false;
- this.shotDelay = 0;
- this.cannonAngle = 0;
- this.cannonAngleMin = -0.7853981633974483;
- this.cannonAngleMax = 0.17453292519943295;
- this.bAutoAim = true;
- this.aCannonPos = new Array();
- this.aCannonPos[0] = new flash.geom.Point(-15,-50);
- this.aCannonPos[3] = new flash.geom.Point(0,-50);
- this.aCannonPos[6] = new flash.geom.Point(15,-50);
- this.aTopPos = new Array();
- this.aTopPos[0] = new flash.geom.Point(49,19);
- this.aTopPos[1] = new flash.geom.Point(59,19);
- this.aTopPos[2] = new flash.geom.Point(65,19);
- this.aTopPos[3] = new flash.geom.Point(65,19);
- this.aTopPos[4] = new flash.geom.Point(65,19);
- this.aTopPos[5] = new flash.geom.Point(72,19);
- this.aTopPos[6] = new flash.geom.Point(84,19);
- this.rope = new Rope(this);
- this.ropePos = new flash.geom.Point(0,-24);
- this.refGame.setFuelGauge(this.fuel);
- this.refGame.setChafsGauge(this.chafs);
- this.refGame.setOnBoardGauge(0,this.maxLoad);
- this.aBottom = new Array();
- this.aBottom[0] = {x0:-22,x1:2};
- this.aBottom[3] = {x0:-12,x1:12};
- this.aBottom[6] = {x0:-2,x1:22};
- }
- function getPosition(Void)
- {
- return this.position.clone();
- }
- function getScreenPos(Void)
- {
- return this.screenPos.clone();
- }
- function getVelocity(Void)
- {
- return this.speed.clone();
- }
- function step(aTargets, aPlatforms)
- {
- if(this.bDestroyed)
- {
- return undefined;
- }
- this.keyControl();
- if(this.bOnPlatform)
- {
- this.acc.x = 0;
- }
- this.bOnPlatform = false;
- if(this.rope.bHasCargo)
- {
- var _loc7_ = this.rope.refCargo.weightFactor;
- if(_loc7_ > 1 && this.rope.length >= 50)
- {
- this.acc.y -= 0.1;
- this.acc.x /= _loc7_;
- this.acc.y /= _loc7_;
- }
- }
- if(this.fuel > 0)
- {
- if(!this.bGodMode)
- {
- this.fuel -= 0.05;
- if(this.fuel < 30 && !this.bFuelSnd)
- {
- this.bFuelSnd = true;
- Sounds.playSound("warning_alarm",99999);
- }
- else if(this.fuel > 30 && this.bFuelSnd)
- {
- this.bFuelSnd = false;
- Sounds.stopSound("warning_alarm");
- }
- }
- }
- else
- {
- this.acc.y = -0.2;
- }
- this.refGame.setFuelGauge(this.fuel);
- if(this.bTurn || this.frame != 0 && this.frame != 3 && this.frame != 6)
- {
- if(this.turnDelay-- < 0)
- {
- this.frame += this.turnDir;
- this.turnDelay = 1;
- if(this.frame <= 0)
- {
- this.frame = 0;
- if(!this.bTurn)
- {
- this.bTurn = false;
- }
- }
- else if(this.frame >= 6)
- {
- this.frame = 6;
- if(!this.bTurn)
- {
- this.bTurn = false;
- }
- }
- }
- }
- var _loc2_ = new flash.geom.Point();
- _loc2_.x = this.position.x;
- _loc2_.y = this.position.y - 25;
- switch(this.frame)
- {
- case 0:
- _loc2_.x -= 15 * Math.cos(- this.rotation);
- _loc2_.y += 15 * Math.sin(- this.rotation);
- break;
- case 6:
- _loc2_.x += 15 * Math.cos(this.rotation);
- _loc2_.y += 15 * Math.sin(this.rotation);
- }
- if(this.bAutoAim)
- {
- var _loc8_ = this.findNearest(aTargets,true);
- if(_loc8_ != null)
- {
- var _loc9_ = _loc8_.getPosition();
- var _loc11_ = _loc9_.x - _loc2_.x;
- var _loc10_ = _loc9_.y - _loc2_.y;
- var _loc13_ = Math.atan2(_loc10_,_loc11_);
- this.cannonAngle = _loc13_ - this.rotation;
- if(this.frame == 6)
- {
- if(this.cannonAngle > this.cannonAngleMax)
- {
- this.cannonAngle = this.cannonAngleMax;
- }
- else if(this.cannonAngle < this.cannonAngleMin)
- {
- this.cannonAngle = this.cannonAngleMin;
- }
- }
- else if(this.frame == 0)
- {
- if(this.cannonAngle > 0 && this.cannonAngle < 3.141592653589793 - this.cannonAngleMax)
- {
- this.cannonAngle = 3.141592653589793 - this.cannonAngleMax;
- }
- else if(this.cannonAngle < 0 && this.cannonAngle > -3.141592653589793 - this.cannonAngleMin)
- {
- this.cannonAngle = -3.141592653589793 - this.cannonAngleMin;
- }
- }
- }
- else
- {
- this.cannonAngle = this.frame != 6 ? 3.141592653589793 : 0;
- }
- }
- var _loc3_ = this.rotation + this.cannonAngle;
- if(this.frame == 0)
- {
- _loc3_ = this.rotation + this.cannonAngle;
- }
- if(this.bShot && (this.frame == 0 || this.frame == 6 || this.frame == 3))
- {
- if(this.shotDelay-- < 0)
- {
- this.shotDelay = 3;
- var _loc14_ = true;
- var _loc5_ = new flash.geom.Point(0,0);
- var _loc4_ = 13;
- switch(this.frame)
- {
- case 0:
- _loc5_ = new flash.geom.Point(_loc4_ * Math.cos(_loc3_),_loc4_ * Math.sin(_loc3_));
- _loc2_.y -= Math.round(4 * Math.random());
- break;
- case 3:
- _loc5_ = new flash.geom.Point(0,- _loc4_);
- break;
- case 6:
- _loc5_ = new flash.geom.Point(_loc4_ * Math.cos(_loc3_),_loc4_ * Math.sin(_loc3_));
- _loc2_.y -= Math.round(4 * Math.random());
- }
- _loc5_.x += this.speed.x;
- this.refGame.createShot(_loc14_,_loc2_,_loc5_);
- }
- }
- if(this.chafDelay-- < 0)
- {
- this.chafDelay = 0;
- }
- if(this.bChaf && this.chafDelay == 0 && this.chafs > 0)
- {
- this.chafDelay = 10;
- this.chafs = this.chafs - 1;
- this.refGame.setChafsGauge(this.chafs);
- var _loc12_ = this.position.clone();
- var _loc6_ = new flash.geom.Point();
- if(this.speed.x == 0)
- {
- this.speed.x = 4.9e-324;
- }
- if(this.speed.y == 0)
- {
- this.speed.y = 4.9e-324;
- }
- _loc6_.x = (- (0 + 1 * Math.random())) * Math.abs(this.speed.x) / this.speed.x;
- _loc6_.y = (- (0 + 1 * Math.random())) * Math.abs(this.speed.y) / this.speed.y;
- this.refGame.createChaf(_loc12_,_loc6_);
- }
- this.backFrame = this.backFrame + 1;
- this.backFrame %= 7;
- this.topFrame = this.topFrame + 1;
- this.topFrame %= 14;
- this.acc.y -= Game.gravity;
- this.speed.x += this.acc.x;
- this.speed.y += this.acc.y;
- this.speed.x *= this.airDrag;
- this.speed.y *= this.airDrag;
- this.position.x += this.speed.x;
- this.position.y += this.speed.y;
- if(this.position.x < 0)
- {
- this.position.x = 0;
- this.speed.x -= this.speed.x * 0.1;
- }
- else if(this.position.x > this.refGame.levelWidth)
- {
- this.position.x = this.refGame.levelWidth;
- this.speed.x -= this.speed.x * 0.1;
- }
- if(this.position.y < 50)
- {
- this.position.y = 50;
- this.die();
- }
- else if(this.position.y > 340)
- {
- this.position.y = 340;
- this.speed.y = 0;
- }
- this.rotation = -12.566370614359172 * this.speed.x / 180;
- if(this.rotation > this.maxRot)
- {
- this.rotation = this.maxRot;
- }
- else if(this.rotation < - this.maxRot)
- {
- this.rotation = - this.maxRot;
- }
- var _loc15_ = new flash.geom.Point(24 * Math.sin(this.rotation),-24 * Math.cos(this.rotation));
- this.ropeEndPos = this.rope.step(this.position.add(_loc15_),this.speed);
- this.checkPlatforms(aPlatforms);
- if(!this.bOnPlatform)
- {
- if(this.checkCollision())
- {
- this.die();
- }
- }
- }
- function draw(levelWidth)
- {
- if(!this.bDestroyed)
- {
- this.bmpTmp.fillRect(this.bmpTmp.rectangle,0);
- if(this.frame == 0)
- {
- this.drawTopRot(this.aTopPos[this.frame]);
- this.drawChopper();
- this.drawBackRot();
- }
- else if(this.frame == 6)
- {
- this.drawBackRot();
- this.drawTopRot(this.aTopPos[this.frame]);
- this.drawChopper();
- }
- else
- {
- this.drawTopRot(this.aTopPos[this.frame]);
- this.drawChopper();
- }
- var _loc3_ = new flash.geom.Matrix();
- _loc3_.translate((- this.bmpTmp.width) / 2,(- this.bmpTmp.height) / 2);
- var _loc5_ = new flash.geom.Matrix();
- _loc5_.rotate(- this.rotation);
- _loc3_.concat(_loc5_);
- var _loc13_ = this.bmpTmp.width;
- var _loc11_ = this.bmpTmp.height;
- var _loc2_ = Game.screenW * 0.5;
- if(this.position.x < Game.screenW * 0.5)
- {
- _loc2_ = this.position.x;
- }
- else if(this.position.x > levelWidth - Game.screenW * 0.5)
- {
- _loc2_ *= 2;
- _loc2_ -= levelWidth - this.position.x;
- }
- var _loc4_ = new flash.geom.Matrix();
- _loc4_.translate(_loc2_,this.screenH - this.position.y);
- _loc3_.concat(_loc4_);
- var _loc7_ = null;
- var _loc6_ = "normal";
- var _loc8_ = null;
- var _loc10_ = true;
- this.screenPos.y = this.position.y;
- this.screenPos.x = _loc2_;
- this.bmpCanvas.draw(this.bmpTmp,_loc3_,_loc7_,_loc6_,_loc8_,_loc10_);
- if(this.bShowExplosion)
- {
- this.drawExplosion(this.screenPos,false);
- }
- var _loc9_ = new flash.geom.Point(24 * Math.sin(this.rotation),-24 * Math.cos(this.rotation));
- this.rope.draw(this.screenPos.add(_loc9_));
- }
- else
- {
- this.drawExplosion(this.screenPos,true);
- }
- }
- function drawBackRot(Void)
- {
- var _loc3_ = new flash.geom.Rectangle(0,23 * this.backFrame,23,23);
- var _loc2_ = new flash.geom.Point();
- if(this.frame == 0)
- {
- _loc2_.x = 105;
- _loc2_.y = 0;
- }
- else if(this.frame == 6)
- {
- _loc2_.x = 1;
- _loc2_.y = 0;
- }
- this.bmpTmp.copyPixels(this.bmpBackRot,_loc3_,_loc2_,null,null,true);
- }
- function drawTopRot(pos)
- {
- pos = new flash.geom.Point(65,15);
- if(this.topFrame % 2 == 0)
- {
- var _loc3_ = new flash.geom.Point(pos.x - this.bmpTopRot.width / 2,pos.y - this.bmpTopRot.height);
- this.bmpTmp.copyPixels(this.bmpTopRot,this.bmpTopRot.rectangle,_loc3_,null,null,true);
- }
- }
- function drawChopper(Void)
- {
- if(this.bShowWheels)
- {
- if(this.frameWheels < 6)
- {
- this.frameWheels += 2;
- }
- var _loc2_ = new flash.geom.Rectangle(0,10 * Math.round(this.frame / 3),130,10);
- var _loc3_ = new flash.geom.Point(0,41 + this.frameWheels);
- this.bmpTmp.copyPixels(this.bmpWheels,_loc2_,_loc3_,null,null,true);
- }
- else if(this.frameWheels > 0)
- {
- if(this.frame % 3 != 0)
- {
- this.frameWheels = 0;
- }
- _loc2_ = new flash.geom.Rectangle(0,10 * Math.round(this.frame / 3),130,10);
- _loc3_ = new flash.geom.Point(0,41 + this.frameWheels);
- this.bmpTmp.copyPixels(this.bmpWheels,_loc2_,_loc3_,null,null,true);
- this.frameWheels -= 2;
- }
- _loc2_ = new flash.geom.Rectangle(0,53 * this.frame,130,53);
- _loc3_ = new flash.geom.Point(0,0);
- this.bmpTmp.copyPixels(this.bmpChopper,_loc2_,_loc3_,null,null,true);
- }
- function drawExplosion(pos, bRemove)
- {
- var _loc3_ = _root.attachMovie("explosion0","mcExp",_root.getNextHighestDepth());
- _loc3_.gotoAndStop(this.frameExp + 1);
- var _loc4_ = new flash.geom.Matrix();
- _loc4_.translate(pos.x,Game.screenH - pos.y);
- this.bmpCanvas.draw(_loc3_,_loc4_,null,null,null,true);
- _loc3_.removeMovieClip();
- this.frameExp = this.frameExp + 1;
- if(this.frameExp == 35)
- {
- if(bRemove)
- {
- this.onEndDeadAnim();
- }
- else
- {
- this.bShowExplosion = false;
- }
- }
- }
- function keyControl(Void)
- {
- var _loc3_ = 38;
- var _loc7_ = 40;
- var _loc4_ = 37;
- var _loc6_ = 39;
- var _loc2_ = 67;
- var _loc9_ = 88;
- var _loc5_ = 90;
- var _loc8_ = 32;
- this.acc.y = 0;
- if(Key.isDown(_loc3_))
- {
- this.acc.y += 0.25;
- if(this.acc.y > this.accMax.y)
- {
- this.acc.y = this.accMax.y;
- }
- }
- else if(Key.isDown(_loc7_))
- {
- this.acc.y -= 0.25;
- if(this.acc.y < - this.accMax.y)
- {
- this.acc.y = - this.accMax.y;
- }
- }
- this.acc.x = 0;
- if(!this.bOnPlatform)
- {
- if(Key.isDown(_loc4_))
- {
- this.acc.x = -0.3;
- if(!this.bShot && (!this.bTurn || this.turnDir == 1))
- {
- this.bTurn = true;
- this.turnDir = -1;
- this.turnDelay = 0;
- }
- }
- else if(Key.isDown(_loc6_))
- {
- this.acc.x = 0.3;
- if(!this.bShot && (!this.bTurn || this.turnDir == -1))
- {
- this.bTurn = true;
- this.turnDir = 1;
- this.turnDelay = 0;
- }
- }
- else
- {
- this.bTurn = false;
- }
- }
- if(Key.isDown(_loc5_))
- {
- this.bChaf = true;
- }
- else
- {
- this.bChaf = false;
- }
- if(Key.isDown(_loc2_) && !this.bShot)
- {
- this.bShot = true;
- Sounds.playSound("ak47",99999);
- }
- else if(!Key.isDown(_loc2_) && this.bShot)
- {
- this.bShot = false;
- Sounds.stopSound("ak47");
- }
- if(Key.isDown(_loc8_) && this.aHostTaken.length < this.maxLoad)
- {
- if(!this.bRopePress)
- {
- this.bRopePress = true;
- this.rope.switchMode();
- }
- }
- else
- {
- this.bRopePress = false;
- }
- }
- function getDamage(damage)
- {
- this.energy -= damage;
- if(this.energy <= 0)
- {
- this.die();
- }
- else
- {
- this.frameExp = 0;
- this.bShowExplosion = true;
- }
- }
- function die(Void)
- {
- if(this.bGodMode)
- {
- return undefined;
- }
- Sounds.stopSound("CHOPPER2");
- Sounds.playSound("bazooka");
- this.bDestroyed = true;
- this.frameExp = 0;
- Game.getInstance().removeHostage(this.rope.refCargo);
- if(this.rope.refCargo.sType == "vehicle")
- {
- this.rope.switchMode();
- }
- }
- function findNearest(aObjects, bInFront)
- {
- var _loc11_ = aObjects.length;
- var _loc8_ = 1.7976931348623157e+308;
- var _loc6_ = 1.7976931348623157e+308;
- var _loc10_ = null;
- var _loc9_ = null;
- var _loc2_ = 0;
- while(_loc2_ < _loc11_)
- {
- if(aObjects[_loc2_].bOnScreen)
- {
- var _loc4_ = aObjects[_loc2_].getPosition();
- var _loc7_ = _loc4_.subtract(this.position);
- var _loc3_ = _loc7_.length;
- if(_loc3_ < _loc8_)
- {
- _loc8_ = _loc3_;
- _loc10_ = aObjects[_loc2_];
- }
- if(this.frame == 0 && _loc4_.x < this.position.x && _loc3_ < _loc6_ || this.frame == 6 && _loc4_.x > this.position.x && _loc3_ < _loc6_)
- {
- _loc6_ = _loc3_;
- _loc9_ = aObjects[_loc2_];
- }
- }
- _loc2_ = _loc2_ + 1;
- }
- return !bInFront ? _loc10_ : _loc9_;
- }
- function increaseLoad(id, index)
- {
- this.aHostTaken.push({id:id,index:index});
- this.refGame.setOnBoardGauge(this.aHostTaken.length,this.maxLoad);
- if(this.aHostTaken.length >= this.maxLoad)
- {
- this.refGame.mcAlert.gotoAndPlay("show");
- }
- }
- function onEndDeadAnim(Void)
- {
- this.refGame.onLooseLife();
- }
- function checkCollision(Void)
- {
- var _loc1_ = new flash.geom.Point(0,0);
- return Game.bmpDead.hitTest(_loc1_,50,Game.bmpChopper,_loc1_,254);
- }
- function checkPlatforms(aPlatforms)
- {
- this.bOnPlatform = false;
- var _loc7_ = aPlatforms.length;
- var _loc10_ = 40;
- var _loc9_ = this.height;
- var _loc4_ = 0;
- while(_loc4_ < _loc7_)
- {
- var _loc2_ = aPlatforms[_loc4_];
- if(_loc2_.bOnScreen)
- {
- var _loc3_ = undefined;
- if(this.frame != 0 && this.frame != 3 && this.frame != 6)
- {
- _loc3_ = this.aBottom[3];
- }
- else
- {
- _loc3_ = this.aBottom[this.frame];
- }
- var _loc6_ = this.position.x + _loc3_.x0;
- var _loc5_ = this.position.x + _loc3_.x1;
- if(_loc2_.plaPos.x < _loc6_ && _loc2_.plaPos.x + _loc2_.plaWidth > _loc5_ && this.position.y > _loc2_.plaPos.y)
- {
- if(this.position.y - _loc2_.plaPos.y < this.height / 2 + 2)
- {
- if(!this.bShowWheels)
- {
- this.bShowWheels = true;
- this.frameWheels = 0;
- }
- if(this.speed.length < 2)
- {
- if(this.acc.y <= 0)
- {
- this.speed.x = 0;
- this.speed.y = 0;
- this.rotation = 0;
- this.position.y = 1 + _loc2_.plaPos.y + this.height / 2;
- }
- this.bOnPlatform = true;
- this.refGame.actionOnPlatform(_loc2_.sType,_loc2_.position);
- break;
- }
- }
- else if(this.position.y - _loc2_.plaPos.y < this.height / 2 + 3)
- {
- if(!this.bShowWheels)
- {
- this.bShowWheels = true;
- this.frameWheels = 0;
- }
- }
- else
- {
- this.bShowWheels = false;
- }
- }
- }
- _loc4_ = _loc4_ + 1;
- }
- }
- }
-